/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package bankingsystem;

import java.util.Calendar;

/**
 *FixedAccount class defined the model of fixed account
 * @author malith
 */
public class FixedAccount extends Account {

    private int duration;
    private float interestRate;

    public FixedAccount(String accountNo, Customer customer, float balance, Calendar startDate, int duration, float interestRate) {
        //initialize the variables
        super(accountNo, customer, balance, startDate);
        this.duration = duration;
        this.interestRate = interestRate;

    }

    /**
     * method to update the account
     * @return boolean value according to the renew status
     */
    public boolean autoRenew() {
        Calendar today = Calendar.getInstance();        //get the current time
        Calendar endDate = startDate;                   //calculate the endDate
        endDate.add(Calendar.MONTH, duration);
        if (endDate.compareTo(today) < 0) {               //if endDate<today it means account has expired
            startDate = today;
            balance = balance * (1 + (interestRate / 100));
            return true;
        }
        return false;
    }

    /**
     * method to show the account details
     *
     */
    @Override
    public void show() {
        System.out.println("\n--Fixed account " + this.accountNo + " details:--"
                + "\nHolder ID: " + this.customer.getCustomerID()
                + "\nBalance: " + Float.toString(this.balance)
                + "\nInterest rate: " + Float.toString(this.interestRate));

    }

    /**
     * Account closing method
     *
     */
    public void remove() {
        boolean state = autoRenew();
        if (state == true) {                    //Check weather cutomer has any interest
            System.out.println("Your Total Balance is:" + balance + "& you closed your account");
            balance = 0;

        } else {
            System.out.println("You Do not have an interest & You Closed your account");

        }
    }

    /**
     * method for check weather customer has an interest & status
     *
     */
    public void checkInterest() {
        Calendar today = Calendar.getInstance();        //get the current time
        Calendar endDate = startDate;                  //calculate the endDate
        endDate.add(Calendar.MONTH, duration);
        if (endDate.compareTo(today) < 0) {              //if endDate<today it means account has expired
            System.out.println("Your Interest is:" + (balance * interestRate / 100));

        } else {
            System.out.println("You dont have interest yet");
        }
    }

    /**
     * getters for private variables
     * @return values accordingly
     */
    public String getAccountNo() {
        return this.accountNo;
    }

    public float getInterestRate() {
        return this.interestRate;
    }

    public int getDuration() {
        return this.duration;
    }

    /**
     * setters for private variables
     *
     */
    public void setAccountNo(String accountNo) {
        this.accountNo = accountNo;
    }

    public void setInterestRate(float interestRate) {
        this.interestRate = interestRate;
    }

    public void setDuration(int duration) {
        this.duration = duration;
    }
}
